<?php

namespace App\Http\Controllers\Api\V1\Frontend;

use App\Http\Controllers\BaseController;
use App\Http\Requests\Api\V1\Customer\Customer\CreateRequest;
use App\Models\Customer\Customer;
use App\Transformers\Frontend\CustomerTransformer;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;

class CustomerController extends BaseController
{

    public function index()
    {
        $user = \Auth::user();
        return $this->response->item($user, new CustomerTransformer());
    }

    public function store(CreateRequest $request)
    {
        $model = \DB::transaction(function () use ($request) {
            $attributes = $request->validated();
            $user = \Auth::user();
            $user->tel = $attributes['tel'];
            $user->save();
            $info = $user->info;
            $info->province = $attributes['province'];
            $info->city = $attributes['city'];
            $info->privilege = $attributes['privilege'];
            $info->address = $attributes['address'];
            $info->save();
        });
        return [
            'code' => '0000', 'message' => '操作成功', 'data' => true
        ];
    }
}